package com.component;

import javax.swing.JFrame;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import com.base.standardization;
import com.data.Data;
import com.db.service.UserServer;
import com.db.sevent.UserEvent;
import com.main.RunFrame;

import util.JDBCUtiles;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Map;

import javax.swing.JButton;
import javax.swing.JLabel;

public class LogingFrame extends JFrame implements standardization{
	public JTextField userNmae;
	public JPasswordField passWord;
	private JButton loginBt;
	
	public static LogingFrame mainFrame = null;
	
	private static class ClassInstance{
		private static final LogingFrame instance = new LogingFrame();
	}
	
	public  static LogingFrame getInstance() {
		return ClassInstance.instance;
	}
	
	public LogingFrame() {
		initFrame();
		userNmae = new JTextField();
		passWord = new JPasswordField();
		loginBt = new JButton("登录");
		
		initOther();
		initLayout();
		event();
		getContentPane().add(passWord);
		getContentPane().add(loginBt);
		getContentPane().add(userNmae);
		
		JLabel label = new JLabel("账号：");
		label.setBounds(63, 76, 54, 15);
		getContentPane().add(label);
		
		JLabel label_1 = new JLabel("密码：");
		label_1.setBounds(63, 117, 54, 15);
		getContentPane().add(label_1);
		initEvent();
		getRootPane().setDefaultButton(loginBt); //回车触发

	}

	private void initFrame() {
		getContentPane().setLayout(null);
		setTitle(Data.config.LoginFrameTitle);
		int WIDTH = Data.config.LogingFrameWIDTH;
		int HEIGHT = Data.config.LogingFrameHEIGHT;
		setSize(WIDTH,HEIGHT);
		setLocationRelativeTo(null);
		setDefaultCloseOperation(EXIT_ON_CLOSE);

		
	}

	@Override
	public void initLayout() {
		userNmae.setBounds(120, 69, 158, 30);
		passWord.setBounds(120, 110, 158, 30);
		loginBt.setBounds(120, 161, 159, 35);
	}
	@Override
	public void initOther() {
		userNmae.setColumns(10);
		passWord.setColumns(10);
	
	}
	@Override
	public void event() {
		loginBt.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				new UserEvent().login();
			}
		});
	}
	@Override
	public void initEvent() {
		
	}
//	public void login() {
//		String username = userNmae.getText();
//		String password = new String(passWord.getPassword());
//		Map<String, String> data = UserApi.Login.POST(username, password);
//		System.out.println(data);
//		if(data.get("code").toString().equals("2000")) {
//			setVisible(false);
//			new RunFrame();
//		}else {
//			System.out.println(data.get("msg"));
//		}
//		
//	}
	public static void main(String[] args) {
		LogingFrame.getInstance().setVisible(true);
		}
}
